API: Make gdk_cairo_create() take a GdkWindow
authorBenjamin Otte <otte@redhat.com>
Wed, 6 Oct 2010 17:12:27 +0000 (19:12 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 2 Dec 2010 19:17:28 +0000 (20:17 +0100)
This is not strictly an API change as GdkDrawable is typedeffed to
GdkWindow, but it changes the header, so I'm marking it as such.
gdk_cairo_create() can only be used with windows these days, so it makes
sense to pass a window. With that, we can alseo remove the
set_cairo_clip() vfunc from GdkDrawable and implement it inside
gdkwindow.c.

gdk/gdkcairo.c
gdk/gdkcairo.h
gdk/gdkdrawable.h
gdk/gdkwindow.c

index a554241fffe5c6108613762d8b56f07a4cbe29c8..7fe0ccc770e8890a0d99cbae8b2d45f5d749a578 100644 (file)
  */
 
 
-/**
- * gdk_cairo_create:
- * @drawable: a #GdkDrawable
- * 
- * Creates a Cairo context for drawing to @drawable.
- *
- * <note><para>
- * Note that due to double-buffering, Cairo contexts created 
- * in a GTK+ expose event handler cannot be cached and reused 
- * between different expose events. 
- * </para></note>
- *
- * Return value: A newly created Cairo context. Free with
- *  cairo_destroy() when you are done drawing.
- * 
- * Since: 2.8
- **/
-cairo_t *
-gdk_cairo_create (GdkDrawable *drawable)
-{
-  cairo_surface_t *surface;
-  cairo_t *cr;
-    
-  g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
-
-  surface = _gdk_drawable_ref_cairo_surface (drawable);
-  cr = cairo_create (surface);
-
-  if (GDK_DRAWABLE_GET_CLASS (drawable)->set_cairo_clip)
-    GDK_DRAWABLE_GET_CLASS (drawable)->set_cairo_clip (drawable, cr);
-    
-  cairo_surface_destroy (surface);
-
-  return cr;
-}
-
 /**
  * gdk_cairo_get_clip_rectangle:
  * @cr: a cairo context
index f594f8bec7d8a464c468505f865993c85619f99d..67e08aa933ef6939147a8d7fc2e88c6e7c76a5de 100644 (file)
@@ -31,7 +31,7 @@
 
 G_BEGIN_DECLS
 
-cairo_t *gdk_cairo_create            (GdkDrawable        *drawable);
+cairo_t *gdk_cairo_create            (GdkWindow          *window);
 gboolean gdk_cairo_get_clip_rectangle(cairo_t            *cr,
                                       GdkRectangle       *rect);
 
index a32c18524f7b3ee1e52209bcd877713c61ffb4eb..24fa1228510467d0ff658beccced76adc79ee8c3 100644 (file)
@@ -67,9 +67,6 @@ struct _GdkDrawableClass
 
   cairo_surface_t *(*ref_cairo_surface) (GdkDrawable *drawable);
 
-  void         (*set_cairo_clip)      (GdkDrawable *drawable,
-                                      cairo_t *cr);
-
   cairo_surface_t * (*create_cairo_surface) (GdkDrawable *drawable,
                                             int width,
                                             int height);
index 01c5749e7a9b06dd5e08a5e1e779dc2dbc576268..bb466439cdfcece843f9e6abed4f0b9a09f177af 100644 (file)
@@ -224,8 +224,6 @@ static cairo_surface_t *gdk_window_create_cairo_surface (GdkDrawable *drawable,
                                                         int width,
                                                         int height);
 static void             gdk_window_drop_cairo_surface (GdkWindowObject *private);
-static void             gdk_window_set_cairo_clip    (GdkDrawable *drawable,
-                                                     cairo_t *cr);
 
 static cairo_region_t*   gdk_window_get_clip_region        (GdkDrawable *drawable);
 static cairo_region_t*   gdk_window_get_visible_region     (GdkDrawable *drawable);
@@ -385,7 +383,6 @@ gdk_window_class_init (GdkWindowObjectClass *klass)
 
   drawable_class->ref_cairo_surface = gdk_window_ref_cairo_surface;
   drawable_class->create_cairo_surface = gdk_window_create_cairo_surface;
-  drawable_class->set_cairo_clip = gdk_window_set_cairo_clip;
   drawable_class->get_clip_region = gdk_window_get_clip_region;
   drawable_class->get_visible_region = gdk_window_get_visible_region;
 
@@ -2818,6 +2815,23 @@ gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect)
   return TRUE;
 }
 
+static cairo_t *
+gdk_cairo_create_for_impl (GdkWindow *window)
+{
+  GdkWindowObject *priv;
+  cairo_surface_t *surface;
+  cairo_t *cr;
+
+  priv = (GdkWindowObject*) window;
+
+  surface = _gdk_drawable_ref_cairo_surface (priv->impl);
+  cr = cairo_create (surface);
+
+  cairo_surface_destroy (surface);
+
+  return cr;
+}
+
 /* Ensure that all content related to this (sub)window is pushed to the
    native region. If there is an active paint then that area is not
    pushed, in order to not show partially finished double buffers. */
@@ -2858,7 +2872,7 @@ gdk_window_flush_implicit_paint (GdkWindow *window)
       cairo_region_subtract (paint->region, region);
 
       /* Some regions are valid, push these to window now */
-      cr = gdk_cairo_create (private->impl);
+      cr = gdk_cairo_create_for_impl (window);
       gdk_cairo_region (cr, region);
       cairo_clip (cr);
       cairo_set_source_surface (cr, paint->surface, 0, 0);
@@ -2890,7 +2904,7 @@ gdk_window_end_implicit_paint (GdkWindow *window)
       cairo_t *cr;
 
       /* Some regions are valid, push these to window now */
-      cr = gdk_cairo_create (private->impl);
+      cr = gdk_cairo_create_for_impl (window);
       gdk_cairo_region (cr, paint->region);
       cairo_clip (cr);
       cairo_set_source_surface (cr, paint->surface, 0, 0);
@@ -3727,11 +3741,35 @@ gdk_window_ref_cairo_surface (GdkDrawable *drawable)
   return surface;
 }
 
-static void
-gdk_window_set_cairo_clip (GdkDrawable *drawable,
-                          cairo_t *cr)
+/**
+ * gdk_cairo_create:
+ * @drawable: a #GdkWindow
+ * 
+ * Creates a Cairo context for drawing to @window.
+ *
+ * <note><warning>
+ * Note that calling cairo_reset_clip() on the resulting #cairo_t will
+ * produce undefined results, so avoid it at all costs.
+ * </warning></note>
+ *
+ * Return value: A newly created Cairo context. Free with
+ *  cairo_destroy() when you are done drawing.
+ * 
+ * Since: 2.8
+ **/
+cairo_t *
+gdk_cairo_create (GdkWindow *window)
 {
-  GdkWindowObject *private = (GdkWindowObject*) drawable;
+  GdkWindowObject *private;
+  cairo_surface_t *surface;
+  cairo_t *cr;
+    
+  g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
+
+  private = (GdkWindowObject*) window;
+
+  surface = _gdk_drawable_ref_cairo_surface (window);
+  cr = cairo_create (surface);
 
   if (!private->paint_stack)
     {
@@ -3765,6 +3803,10 @@ gdk_window_set_cairo_clip (GdkDrawable *drawable,
          cairo_clip (cr);
        }
     }
+    
+  cairo_surface_destroy (surface);
+
+  return cr;
 }
 
 /* Code for dirty-region queueing